<?php
/**
 * wp-foundation widgets.php
 */
?>
<?php
//WIDGET, ABOVE HEADER
function aboveheader_widgets_init() {
    register_sidebar(array(
       	'name' => 'Header Above',
       	'id' => 'header-above',
       	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
       	'after_widget' => "",
		'before_title' => "<h3 class=\"widgettitle\">",
		'after_title' => "</h3>\n",
    ));}
add_action( 'init', 'aboveheader_widgets_init' );
//END WIDGET, ABOVE HEADER

// WIDGET, ADD ABOVE HEADER
function header_above_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('header-above') ) {
    echo '<div id="header-above">'. "\n" . '<ul class="xoxo">' . "\n";
    dynamic_sidebar('header-above');
    echo '' . "\n" . '</div><!-- eof #header-above -->'. "\n";
}}
add_action('foundation_aboveheader', 'header_above_add', 8);
//END WIDGET, ADD ABOVE HEADER

//WIDGET, BELOW HEADER
function belowheader_widgets_init() {
    register_sidebar(array(
       	'name' => 'Header Below',
       	'id' => 'header-below',
       	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
       	'after_widget' => "",
		'before_title' => "<h3 class=\"widgettitle\">",
		'after_title' => "</h3>\n",
    ));}
add_action( 'init', 'belowheader_widgets_init' );
//END WIDGET, BELOW HEADER

// WIDGET, ADD BELOW HEADER
function header_below_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('header-below') ) {
    echo '<div id="header-below">'. "\n" . '<ul class="xoxo">' . "\n";
    dynamic_sidebar('header-below');
    echo '' . "\n" . '</div><!-- eof #header-below -->'. "\n";
}}
add_action('foundation_belowheader', 'header_below_add', 8);
//END WIDGET, ADD BELOW HEADER

//WIDGET, INSIDE Header DIV
function in_header_widgets_init() {
    register_sidebar(array(
       	'name' => 'Inside Header',
       	'id' => 'fd-in-header',
       	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
       	'after_widget' => "",
		'before_title' => "<h3 class=\"widgettitle\">",
		'after_title' => "</h3>\n",
    ));}
add_action( 'init', 'in_header_widgets_init' );
//END WIDGET, INSIDE HEADER DIV

// WIDGET, ADD INSIDE HEADER DIV
function in_header_widgets_add() {
if ( function_exists('dynamic_sidebar') && is_sidebar_active('fd-in-header') ) {
    echo '<div id="fd-in-header">'. "\n" . '<ul class="xoxo">' . "\n";
    dynamic_sidebar('fd-in-header');
    echo '' . "\n" . '</div><!-- eof #fd-in-header -->'. "\n";
}}
add_action('foundation_in_header', 'in_header_widgets_add', 8);
//END WIDGET, ADD INSIDE HEADER DIV


// Register widgetized areas
function theme_widgets_init() {
	
	// Area 1
  register_sidebar( array (
  'name' => 'Primary Widget Area',
  'id' => 'primary-widget-area',
  'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  'after_widget' => "</li>",
	'before_title' => '<h3 class="widget-title">',
	'after_title' => '</h3>',
  ) );

	// Area 2
  register_sidebar( array (
  'name' => 'Secondary Widget Area',
  'id' => 'secondary-widget-area', 
  'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  'after_widget' => "</li>",
	'before_title' => '<h3 class="widget-title">',
	'after_title' => '</h3>',
  ) );
} // end theme_widgets_init

add_action( 'init', 'theme_widgets_init' );


// Pre-set Widgets
$preset_widgets = array (
	'primary-aside'  => array( 'search', 'pages', 'categories', 'archives' ),
	'secondary-aside'  => array( 'links', 'meta' )
);
if ( isset( $_GET['activated'] ) ) {
	update_option( 'sidebars_widgets', $preset_widgets );
}


// Check for static widgets in widget-ready areas
function is_sidebar_active( $index ){
  global $wp_registered_sidebars;

  $widgetcolums = wp_get_sidebars_widgets();
		 
  if ($widgetcolums[$index]) return true;
  
	return false;
} // end is_sidebar_active
?>